package com.hgw.Demo06_MementoPattern.examples;

/**
 * Data time:2021/12/18 21:08
 * StudentID:2019112118
 * Author:hgw
 * Description: 客户端测试类
 */
public class Client {
    public static void main(String[] args) {
        MementoCaretaker mc = new MementoCaretaker();
        Chessman chess = new Chessman("车", 1, 1);
        display(chess);
        mc.setMemento(chess.save());        // 保存状态
        chess.setY(4);
        display(chess);
        mc.setMemento(chess.save());        // 保存状态
        chess.setY(5);
        display(chess);
        System.out.println("****** 悔棋 ******");
        chess.restore(mc.getMemento());     // 恢复状态
        display(chess);
    }

    public static void display(Chessman chess) {
        System.out.println("棋子" + chess.getLabel() + "当前位置为：第" + chess.getX() + "行第" + chess.getY() + "列.");
    }
}
